home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / inwineq2.zip / INWINEQ1.DOC < prev    next >
Text File  |  1991-11-20  |  2KB  |  62 lines

  1. It is frequently desirable for batch files to know whether a DOS program is 
  2. running from within a Windows DOS virtual machine or from the DOS prompt 
  3. alone.  According to Microsoft, it's dangerous to run certain programs, such 
  4. as CHKDSK, while you're in Windows.  Also, at times you may want to display a 
  5. message telling how to switch back to Windows with a hot key.
  6.  
  7. When Windows is running, it creates an environment variable with the name 
  8. `windir' that points to the Windows directory.  Normally, one can test for 
  9. variables with the `==' operator, but `==' assumes that variable names are all 
  10. uppercase, and `windir' is lowercase.  (Microsoft probably did this so the SET 
  11. command couldn't create or change the variable.)  Any reference to `windir' in 
  12. a batch file actually looks for a variable named `WINDIR', which isn't the 
  13. same thing.
  14.  
  15. To circumvent this problem, this small assembly language program searches for 
  16. `windir'.  If it's found, the program returns an ERRORLEVEL of 1; otherwise it 
  17. returns an ERRORLEVEL of 0.  The following batch file, CHKDSK.BAT, shows how 
  18. you can use InWinEQ1 to prevent running CHKDSK from within Windows.  First, 
  19. put CHKDSK.BAT and INWINEQ1.COM in a directory listed in your PATH command and 
  20. rename your DOS directory's CHKDSK.COM to CHKDSK!.COM (depending upon your DOS 
  21. version, CHKDSK may be an EXE program).  When CHKDSK is typed, the batch file 
  22. will check to see if Windows is running.  If it is, InWinEQ1 will return an 
  23. ERRORLEVEL of 1 and the batch file will go directly to the :INWINDOWS line, 
  24. skipping the CHKDSK! command.  You can easily modify this batch file for other 
  25. purposes.
  26.  
  27. CHKDSK.BAT:
  28.  
  29.         @ECHO OFF
  30.         InWinEQ1
  31.         IF ERRORLEVEL 1 GOTO INWINDOWS
  32.         CHKDSK! %1 %2 %3
  33.         GOTO DONE
  34.         :INWINDOWS
  35.         CLS
  36.         ECHO You cannot run CHKDSK from inside Windows!
  37.         :DONE
  38.         ECHO ON
  39.  
  40.  
  41. InWinEQ1.dat:
  42.  
  43.         N InWinEQ1.com
  44.         E100 A1 2C 00 8E C0 BF 00 00 26 8A 05 3C 00 74 25 BE
  45.         E110 3D 01 8A 1C 80 FB 00 74 16 26 8A 05 3A C3 75 04
  46.         E120 47 46 EB EE 47 26 8A 05 0A C0 75 F8 47 EB D9 C6
  47.         E130 06 3C 01 01 B4 4C A0 3C 01 CD 21 00 00 77 69 6E
  48.         E140 64 69 72 3D 00
  49.         RCX
  50.         45
  51.         W
  52.         Q
  53.  
  54. To create InWinEQ1.com, input InWinEQ1.dat into DEBUG by typing: 
  55.         DEBUG < INWINEQ1.DAT 
  56.  
  57.  
  58. Christopher J. Stein
  59. Durham, North Carolina
  60.  
  61. published in PC WORLD DECEMBER 1991
  62.